package com.droidclaimcustomer.bl;

import java.lang.reflect.Type;
import java.text.DateFormat;
import java.util.Date;

import com.droidclaimcustomer.dto.AllClaimInfoForCustomerResultBlDto;
import com.droidclaimcustomer.dto.SessionPkBlDto;
import com.droidclaimcustomer.helper.service.DateDeserializer;
import com.droidclaimcustomer.helper.service.RestfulWebService;
import com.droidclaimcustomer.helper.service.ServiceMethod;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class GetAllClaimInfoForCustomer extends ServiceMethod<AllClaimInfoForCustomerResultBlDto>{
	public static String METHOD_NAME = "GetAllClaimInfoForCustomer";
	private Gson gson;
	private SessionPkBlDto parameter;
	
	public GetAllClaimInfoForCustomer(){
		 gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateDeserializer())
				 		.serializeNulls()
				 		.setDateFormat(DateFormat.LONG)
				 		.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
				 		.setPrettyPrinting()
				 		.create();
	}
	
	@Override
	public String getName() {
		return GetAllClaimInfoForCustomer.METHOD_NAME;
	}

	@Override
	public String getParameter() {
		String result = "";
		
		result = gson.toJson(parameter);
				
		return result;
	}

	public void setParameter(SessionPkBlDto parameter) {
		this.parameter = parameter;
	}
	
	@Override
	public int getMethodType(){
		return RestfulWebService.HTTP_POST;
	}
	
	public AllClaimInfoForCustomerResultBlDto mapResponse(String json){
		if(json.isEmpty()){
			return new AllClaimInfoForCustomerResultBlDto();
		}
		
		Type listType = new TypeToken<AllClaimInfoForCustomerResultBlDto>(){}.getType();
		AllClaimInfoForCustomerResultBlDto result = gson.fromJson(json, listType);
		
		return result;
	}
}
